home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-16 | 6.4 KB | 234 lines | [TEXT/KAHL] |
- /*
- * These may be un-commented for testing.
- */
- // #define FORCE_MONOCHROME 1
- // #define FORCE_RIGHT_JUSTIFY 1
- // #define FORCE_HUGE_FONT 1
- // #define NO_HILITE_SELECTION 1
- /* WindowManager.c */
- /*
- * List In A List Sample
- * WindowManager.c
- * Copyright © 1993-94 Apple Computer Inc.
- *
- * This is a very limited example of using the TwistDown list functions. In
- * particular, note that there is no error handling whatsoever: if the disk
- * being examined has too many files or folders, your program will crash.
- */
- #include "ListInAList.h"
- #include <GestaltEqu.h>
- #include <Script.h>
- /*
- * These configure the window for testing.
- */
- #ifndef FORCE_MONOCHROME
- #define FORCE_MONOCHROME 0
- #endif
- #ifndef FORCE_RIGHT_JUSTIFY
- #define FORCE_RIGHT_JUSTIFY 0
- #endif
- #ifndef FORCE_HUGE_FONT
- #define FORCE_HUGE_FONT 0
- #endif
- #ifndef NO_HILITE_SELECTION
- #define NO_HILITE_SELECTION 0
- #endif
-
- /*
- * MakeHFSBrowserWindow
- * Create a window, the twist-down list, and fill it with file names.
- */
- void
- MakeHFSBrowserWindow(void)
- {
- register BrowserPtr browserPtr;
- WindowPtr theWindow;
- Rect viewRect;
- long response;
- Boolean hasColorQuickDraw;
- Ptr privateStash;
- Str255 work;
-
- hasColorQuickDraw = FALSE;
- if (Gestalt(gestaltQuickdrawVersion, &response) == noErr
- && response >= gestalt8BitQD)
- hasColorQuickDraw = TRUE;
- viewRect = qd.screenBits.bounds;
- InsetRect(&viewRect, 4, 4);
- viewRect.top += (GetMBarHeight() * 2);
- browserPtr = (BrowserPtr) NewPtrClear(sizeof (BrowserRecord));
- if (browserPtr == NULL)
- ExitToShell();
- if (FORCE_MONOCHROME == 0 && hasColorQuickDraw) {
- theWindow = NewCWindow(
- (Ptr) browserPtr, /* Our data storage */
- &viewRect, /* Screen bounds */
- "\pList in a Handle in a List",
- FALSE, /* Initially invisible */
- noGrowDocProc, /* Simple document */
- (WindowPtr) -1L, /* Put in front */
- TRUE, /* Has go away */
- 0 /* No refCon */
- );
- }
- else {
- theWindow = NewWindow(
- (Ptr) browserPtr, /* Our data storage */
- &viewRect, /* Screen bounds */
- "\pList in a Handle in a List",
- FALSE, /* Initially invisible */
- noGrowDocProc, /* Simple document */
- (WindowPtr) -1L, /* Put in front */
- TRUE, /* Has go away */
- 0 /* No refCon */
- );
- }
- if (theWindow == NULL)
- ExitToShell();
- SetPort(theWindow); /* Do this first, or else */
- viewRect = theWindow->portRect;
- TextFont(kListFontNumber);
- #if FORCE_HUGE_FONT
- /*
- * This makes the font size huge so the buttons can easily be placed
- * across multiple monitors in order to test the DeviceLoop algorithm.
- */
- TextSize((viewRect.bottom - viewRect.top) / 8); /* A huge font size */
- #else
- TextSize(kListFontSize);
- #endif
- browserPtr->theList = NewTwistDownList(
- &viewRect, /* Where it goes in the window */
- NULL, /* Draw using DrawText */
- CharWidth('n'), /* Tab indentation amount */
- NO_HILITE_SELECTION, /* Hilite selections? */
- #if FORCE_RIGHT_JUSTIFY
- FALSE
- #else
- (GetSysJust() == 0) /* Current system justification */
- #endif
- );
- if (browserPtr->theList == NULL)
- ExitToShell(); /* Oops */
- ShowWindow(theWindow);
- SelectWindow(theWindow);
- gUpdateMenusNeeded = TRUE;
- ++gOpenWindowCount;
- SetCursor(*GetCursor(watchCursor));
- /*
- * Because EnumerateHFSCatalog can absorb all available memory if you
- * call it for a very large disk (ask me how I know), we grab a chunk
- * of memory that we restore before building and displaying the visible.
- * This isn't a really great solution, but it will do for now.
- */
- privateStash = NewPtr(32768L);
- if (privateStash != NULL) {
- browserPtr->listHead = EnumerateHFSCatalog(
- browserPtr->theList, /* Store in this list */
- 0, /* Initial indent */
- 0, /* Do current volume */
- fsRtDirID /* Start at the root directory */
- );
- DisposePtr(privateStash);
- }
- /*
- * The catalog has been enumerated and the list of files and folders
- * constructed. Display the number of files/folders in the Window title
- * and display the initial list.
- */
- NumToString(CountListElements(browserPtr->listHead), work);
- pstrcat(work, "\p - Files and folders found");
- SetWTitle(theWindow, work);
- CreateVisibleList(browserPtr->theList, browserPtr->listHead);
- }
-
- /*
- * DisposeBrowser
- * The user clicked on the closer. Dispose of the window and its contents.
- */
- void
- DisposeBrowser(
- register BrowserPtr browserPtr
- )
- {
- DisposeTwistDownList(browserPtr->theList);
- DisposeTwistDownHdl(browserPtr->listHead, NULL, 0);
- CloseWindow((WindowPtr) &browserPtr->theWindow);
- DisposePtr((Ptr) browserPtr);
- gUpdateMenusNeeded = TRUE;
- --gOpenWindowCount;
- }
-
- /*
- * ActivateBrowser
- * This is called on activate and deactivate (or suspend/resume) events to enable
- * or disable the window content.
- */
- void
- ActivateBrowser(
- register BrowserPtr browserPtr,
- Boolean activating
- )
- {
- LActivate(activating, browserPtr->theList);
- }
-
- /*
- * DoWindowKeyDown
- */
- void
- DoWindowKeyDown(
- register BrowserPtr browserPtr
- )
- {
- #pragma unused (browserPtr)
-
- /* Nothing happens here */
- }
-
- /*
- * DoContentClick
- * Click in the window. This function decides which element received the click and
- * calls the requisite click handler. In this example, we need only deal with
- * the twist-down list.
- */
- void
- DoContentClick(
- register BrowserPtr browserPtr
- )
- {
- Cell theCell;
- TwistDownClickState clickState;
-
- clickState = DoTwistDownClick(browserPtr->theList, &gEventRecord, &theCell);
- switch (clickState) {
- case kTwistDownNotInList: /* Not in list view rectangle */
- case kTwistDownNoClick: /* Scroll bar or user changed mind */
- break; /* Ignore this click */
- case kTwistDownButtonClick: /* Clicked on expansion button */
- break; /* Done for us */
- case kTwistDownClick: /* Single-click on list datum */
- case kTwistDownDoubleClick: /* Double-click on list datum */
- break; /* Ignore these clicks */
- }
- }
-
- /*
- * UpdateBrowserWinow
- * Process an update event in this window.
- */
- void
- UpdateBrowserWindow(
- register BrowserPtr browserPtr,
- RgnHandle updateRgn
- )
- {
- Rect viewRect;
-
- viewRect = (**(browserPtr->theList)).rView;
- InsetRect(&viewRect, -1, -1);
- FrameRect(&viewRect);
- LUpdate(updateRgn, browserPtr->theList);
- }
-
-